<?php
// +----------------------------------------------------------------------
// | 车保点点首页
// +----------------------------------------------------------------------
// | Author: cart <469714167@qq.com>
// +----------------------------------------------------------------------
// | Datetime: 2018-2-1 09:00:00
// +----------------------------------------------------------------------
// | Copyright: 微量科技
// +----------------------------------------------------------------------
namespace app\ice\controller;
use think\Loader;
use app\wx\model\Area;
class Illegal extends Init
{
    private $IndexModel;
    /**
     * [_initialize 初始化]
     * @return [type] [description]
     * @author carl
     * @version 2018-02-05
     * @copyright wei liang
     */
    protected function _initialize()
    {
        parent::_initialize();
        $this->IndexModel = Loader::model('Index');
    }

    /**
     * [findex 微信车保点点绑定oauth跳转入口]
     * 
     * @return [type] [description]
     * @author carl
     * @version 2018-02-05
     * @copyright wei liang
     */
    
    public function findex() {
        // $weObj = new Wechat ( self::$options );
        // $url = __IP__ . '/Wechat01/Index/bind';
        $url = url('bind/bind');
        $scope = 'snsapi_base';
        $oauth_url = $this->wechat->getOauthRedirect ( $url, "wxbase");
        $this->redirect($oauth_url,302);
    }

    /**
     * [query 提交查询]
     * @return [type] [description]
     */
    public function query()
    {
        $param = input('post.');
        $result = $this->validate($param, 'IndexValidate.query');
            if (true !== $result) {
                return ['code'=>40005,'msg'=>$result,'data'=>[],'status'=>false];
            }
        // $option['engineno'] = 'LVHFR2856J6007094';
        // $option['frameno'] = '1007098';
        // $option['iscity'] = 0;
        // $option['lsEnPrefix'] = 'A';
        // $option['lsnum'] = '58B39';
        // $option['lsprefix'] = urlencode('沪');
        $param['lsprefix'] = urlencode($param['lsprefix']);
        $param['lsnum'] = $param['lsEnPrefix'].$param['lsnum'];
        $res = getIllegalInquiry($param);
        if($res){
            $objData = json_decode($res);
            $res = $objData->result;
            return ['data' => $res, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
        }else{
            return ['data' => $res, 'code' => 400, 'message' => '列表显示成功', 'status' => false];
        }
    }

    /**
     * [getLicensePlate 获取车牌地区信息]
     * @return [res] array [地区信息]
     */
    public function getLicensePlate(){
        $param = input('post.');
        $result = $this->validate($param, 'IndexValidate.level');
            if (true !== $result) {
                return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
            }
        $AreaModel = new Area();
        $res = $AreaModel->getListData($param['level']);
        return ['data' => $res, 'code' => 200, 'message' => '列表显示成功', 'status' => true ];
    }

    /**
     * [getCarorg 获取交管局信息]
     * 
     * @return [type] [description]
     */
    public function getCarorg(){
        $param = input('post.');
        $result = $this->validate($param, 'IndexValidate.weizhang');
            if (true !== $result) {
                return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false ];
            }
        $carorgInfo = getCarorg();
        $carorg = [];
        if($carorgInfo){
            $carorgInfo = json_decode($carorgInfo);
            $carorgList = $carorgInfo->result->data;
            foreach ($carorgList as $key => $value) {
                if($param['carorg'] == $value->carorg){
                    $carorg = $value;
                }
            }
        }
        if(!$carorg){
            return ['data' => '', 'code' => 400, 'message' => '参数不正确或者参数不全', 'status' => false];
        }else{
            return ['data' => $carorg, 'code' => 200, 'message' => '列表显示成功', 'status' => true ];
        }
    }
}